//
//  ScheduleViewController.swift
//  CustomizeCollectionView
//
//  Created by GZOffice_hao on 2019/4/26.
//  Copyright © 2019 VT. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"
private let headerReuseIdentifier = "Header"

class ScheduleViewController: UICollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Register cell classes
//        self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
        let width = collectionView.bounds.width
        collectionView.contentInsetAdjustmentBehavior = .automatic
        
        if let layout = collectionViewLayout as? DIYLayout {
            layout.headerReferenceSize = CGSize(width: width, height: 180)
            layout.itemSize = CGSize(width: width, height: 65)
            layout.maximumStretchHeight = width
//            layout.sectionInsetReference = .fromSafeArea
//            layout.sectionHeadersPinToVisibleBounds = true
        }
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
    
    override var prefersHomeIndicatorAutoHidden: Bool {
        return true
    }
}

extension ScheduleViewController {
    // MARK: UICollectionViewDataSource
    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 20
    }
    
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
//        cell.backgroundColor = UIColor.random
        return cell
    }
    
    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        if kind == UICollectionView.elementKindSectionHeader {
            let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerReuseIdentifier, for: indexPath)
            return header
        } else {
            return super.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, at: indexPath)
        }
    }
}
